package com.masterclient.app.modules.cart.contract;

import com.eoner.baselib.presenter.ThrowableConsumer;
import com.masterclient.app.httpservice.RetrofitUtil2;
import com.masterclient.app.modules.cart.beans.GatherBean;

import io.reactivex.Observable;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
 * Created by TMVPHelper on 2017/07/18
 */
public class GatherGoodsPresenter extends GatherGoodsContract.Presenter {

    @Override
    public void getGatherGoodsList(String page, String pageSize, String activityId, String sort) {
        Observable<GatherBean> observable = RetrofitUtil2.getInstance().getGatherGoodsList(page,pageSize,activityId,sort);
        Disposable disposable = toSubscribe(observable, (Consumer<GatherBean>) bean -> {
            if (bean != null && "0".equals(bean.getCode())) {
                mView.showGatherGoodsList(bean);
            } else {
                mView.showGatherGoodsListFailed(bean.getMsg());
            }
        }, new ThrowableConsumer() {
            @Override
            public void accept(Throwable o) throws Exception {
                super.accept(o);
                mView.showGatherGoodsListFailed("网络异常，请重试");
            }
        });
        mRxManager.add(disposable);
    }
}